<?php
#################################
# Metadata Enhancement for Repositories (MER) 
# This software is an overlay repository search interface that uses a 
# text mined index of terms.
# Copyright (C) 2011  Rory McNicholl (University of London Computer Centre), Robert Drinkall (University College London)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Contact repositories@ulcc.ac.uk
# http://www.ulcc.ac.uk

##################################

include("../mer.php");
$mer = new MER();
$mer->get_search_fields();

#YUK!
$template = file_get_contents($mer->config->repo_path."/archives/".$mer->config->repo_id."/cfg/lang/".$mer->config->lang."/templates/default.xml");
$template = preg_replace(array(
			'/\{\$config\{onload\}\}/',
			'/\{\$config\{base_url\}\}/',
			'/\{\$config\{rel_path\}\}/',
			'/\{\$config\{frontpage\}\}/',
			'/\{\$config\{http_cgiurl\}\}/',
			'/\{\$config\{perl_url\}\}/',
			'/\{\$config\{http_url\}\}/',
			'/\<epc\:print expr="\$config\{rel_path\}"\/\>/',
			'/\<epc\:print expr="\$config\{base_url\}"\/\>/',
			'/\<epc\:pin ref="title" textonly="yes"\/>/',
			'/\<epc:phrase ref=\"archive_name\"\/\>/',
			'/\{phrase\(\'archive_name\'\)\}/'
			),
		array('',
			$mer->config->repo_url,
			$mer->config->repo_url,
			$mer->config->repo_url,
			$mer->config->repo_url.'/cgi',
			$mer->config->repo_url.'/cgi',
			$mer->config->repo_url,
			$mer->config->repo_url,
			$mer->config->repo_url,
			'',
			$mer->config->repo_id
			),
	$template);

$merlin_head = "
<!-- Style sheets -->
<link type=\"text/css\" href=\"{$mer->config->http_root}/css/smoothness/jquery-ui-1.7.2.custom.css\" rel=\"stylesheet\" />
<link rel=\"stylesheet\" href=\"{$mer->config->http_root}/css/ui.daterangepicker.css\" type=\"text/css\" /> 
<link rel=\"stylesheet\" href=\"{$mer->config->http_root}/css/merlin.css\" type=\"text/css\" />
<!-- javascript -->
<!-- jQuery and plugins -->
<script type=\"text/javascript\" src=\"{$mer->config->http_root}/js/jquery-1.3.2.min.js\"></script>
<script type=\"text/javascript\">
	jQuery.noConflict();
</script>
<!-- MERLIN javascript -->
<script type=\"text/javascript\" src=\"{$mer->config->http_root}/js/merlin.js\"><!-- script --></script>";


$merlin_body = "
<div id=\"mer_wrapper\">
<!--<div id=\"mer_menu\"><ul><li id=\"browse_toggle\">Browse</li></ul></div> -->
	<div id=\"main\">
		<div id=\"form\" class=\"column\">
			<div id=\"form-content\" class=\"fieldset\">
				<h1><span>Search for</span></h1>
				<h2><a href=\"#help_box_search\"><img alt=\"?\" src=\"{$mer->config->http_root}/images/help.png\"/></a></h2>
				<form id=\"search_form\" action=\"/cgi/search/simple\" method=\"post\">
					<fieldset id=\"search\" class=\"curve_box\">
						<input type=\"text\" name=\"q\" id=\"search_string\"/>
						<input type=\"submit\" value=\"Search\"/>
						<br style=\"clear: both;\"/>
						<label class=\"nexto\">Number of results to show: </label>
						<select name=\"num_recs\">
							<option>5</option>
							<option>10</option>
							<option selected=\"selected\">20</option>
							<option>50</option>
						</select>
					</fieldset>
					<fieldset id=\"filters\" class=\"curve_box\">
						<label class=\"ontop\">Date range:</label>
						<!--<input type=\"text\" name=\"daterange\" id=\"daterange\"/>-->
						<select name=\"daterange\" id=\"daterange\">
						</select>
						<br style=\"clear: both;\"/>";
						foreach($mer->sf as $field=>$val){
							$merlin_body .= $mer->get_EP_field_menu($field); 
							$merlin_body .= "<br style=\"clear: both;\"/>";
						};
						$merlin_body .= "<label for=\"fullText\">Full-text records only</label>
						<input type=\"checkbox\" class=\"checkBox\" name=\"full_text_status\" id=\"fullText\" value=\"public\"/>
						<br style=\"clear: both;\"/>
					</fieldset>
				</form>
			</div>
		</div>
		<div id=\"terms\" class=\"column\">
			<div id=\"terms_cloud\">
				<div class=\"help_screencast fieldset\">
					<h1><span>Welcome to LASSO - MERLIN</span></h1>
					<h2><a href=\"#help_box_screencast\"><img alt=\"?\" src=\"{$mer->config->http_root}/images/help.png\"/></a></h2>
					<div id=\"screencast\">
<!--						<object id='stUEtSREZORFtYQ1lUU1pfUVVT' width='535' height='334' type='application/x-shockwave-flash' data='http://www.screentoaster.com/swf/STPlayer.swf'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'><param name='movie' value='http://www.screentoaster.com/swf/STPlayer.swf'/><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><param name='flashvars' value='video=stUEtSREZORFtYQ1lUU1pfUVVT'/></object> -->
					</div>
				</div>
			</div>
		</div>
		<div id=\"results\" class=\"column\">
			<div class=\"help_splash fieldset\">
				<h1><span>About LASSO - MERLIN</span></h1>
				<p>Welcome to the experimental search service MERLIN. MERLIN uses the <a href=\"http://lass.ucl.ac.uk\">LEAP Aggregated Search Service Online (LASSO)</a> system to search inside full text documents held in University of London Institutional Repositories.</p>
				<p style=\"font-weight: bold;\">MERLIN:</p>
				<ul>
				   <li> identifies words and concepts which are related to your search</li>
				   <li> presents them as a tag cloud or as a list</li>
				   <li> lets you refine or expand your search using the real language of your discipline</li>
				</ul>
				<p>To use MERLIN, enter a search term. MERLIN will show you results for your search on the right, and a cloud of related terms here in the middle.</p>
				<p>If one of the terms MERLIN shows you seems useful, simply click on it to see the options for adding that term to your search.</p>
				<p>You can see more detail about any of your results by clicking on the title. Click on the logo next to the title to go straight to the item. </p>
			</div>
		</div>
	<br style=\"clear: both;\"/>
	<div id=\"bottom\" class=\"fieldset\">
		<h1><span>Details</span></h1>
		<h2><a href=\"#help_box_splash\"><img alt=\"?\" src=\"{$mer->config->http_root}/images/help.png\"/></a></h2>
	</div>

	</div> <!-- close main -->

	<div id=\"help_box_search\" class=\"help_box\">
		<h2>Help: LASSO search</h2>
		<p>Enter a search term or terms (e.g.'public sector') in the search box.</p>
		<p>You may wish to limit your results to one type of publication (e.g. just journal articles) or to items published in one year.</p>
		<p>You can do this by choosing from the menus below the search box.</p>
		<p>You can also choose to search for full-text items that you can read straight away, or for items that have been peer-reviewed using the tick boxes.</p>
	</div>

	<div id=\"help_box_screencast\" class=\"help_box\">
		<h2>Help: MERLIN screen cast</h2>
		<p>The screencast is designed to demonstrate how to use MERLIN to enrich your search of the LEAP repositories. Click play to view the screencast you can also make the it full screen (Flash required).</p>
	</div>
	<div id=\"help_box_terms_list\" class=\"help_box\">
		<h2>Help: Termine terms list</h2>
		<p>These are the terms that MERLIN has found inside the documents that related to your search. They are the authors' own words and phrases which our text-mining tool has associated with your search. The terms are graded by relevance - the most relevant terms are at the top of the list.</p>
	</div>

	<div id=\"help_box_terms_cloud\" class=\"help_box\">
		<h2>Help: Termine terms cloud</h2>
		<p>These are the terms that MERLIN has found inside the documents that related to your search. They are the authors' own words and phrases which our text-mining tool has associated with your search. The terms are graded by relevance - the larger the type, the more relevant the word.</p>
		<p>You can use the slider (to the right of the cloud) to add more terms to the cloud, or to limit the display to only the most relevant terms. </p>
	</div>

	<div id=\"help_box_results\" class=\"help_box\">
		<h2>Help: Search results</h2>
		<p>This displays the results of your search. If you change your search using the MERLIN cloud, the results shown here will change too. The results panel will show you the title of each matching result, and will tell you which institution from the University of London the result has come from.</p>
		<p>Click on a title to see more information about that item, or click on the logo to go straight to that item in its home repository.</p>
		<p>You can also add items from your results to a marked list by selecting the tick box to the left of the title. </p>
	</div>

	<div id=\"help_box_splash\" class=\"help_box\">
		<h2>Help: Item details</h2>
		<p>When you click on one of your search results, the details of that item will be displayed here.</p>
		<p>The results panel will show you the title of each matching result, and will tell you which institution from the University of London the result has come from.</p>
		<p>You can view more details (including author names and the abstract) in this panel without leaving your results page, saving you time and effort.</p>
		<p>If you find that the item is useful, you can go straight to it by clicking 'go to item' or add it to a marked list by selecting the box in the results list.</p>
	</div>

</div> <!-- close mer_wrapper -->
";

#URGH!
$template = preg_replace('/\<epc\:pin ref="head"\/\>/',$merlin_head, $template);
$template = preg_replace('/\<epc\:pin ref="page"\/\>/',$merlin_body, $template);

print $template;

exit;
